package com.css.modules.lawRepo.controller;

import com.css.common.utils.PageUtils;
import com.css.common.utils.R;
import com.css.modules.lawRepo.entity.LawRepoDocApprovalEntity;
import com.css.modules.lawRepo.service.LawRepoDocApprovalService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/lawRepo/approval")
@Api(value = "/approval", description = "法律法规审批表", tags = "法律法规审批表")
public class LawRepoDocApprovalController {
    @Autowired
    private LawRepoDocApprovalService docApprovalService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数", dataType = "int", paramType = "query", required = true),
    })
    @RequestMapping(value = "/list" ,method = RequestMethod.GET)
    @ApiOperation(value = "法律法规审批表", notes = "返回法律法规审批表",
            produces = "application/json")
    public R list(@ApiParam(name="params" ,hidden = true)@RequestParam Map<String, Object> params){
        PageUtils page = docApprovalService.queryPage(params);
        return R.ok().put("page", page);
    }

    @ApiOperation(value = "根据文档ID查询", produces = "application/json")
    @RequestMapping(value = "/listByDocId{docId}" ,method = RequestMethod.GET)
    public LawRepoDocApprovalEntity findByDocId(@RequestParam("docId") String docId){
        return docApprovalService.findByDocId(docId);
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "添加审批", produces = "application/json")
    public R insert(@RequestBody LawRepoDocApprovalEntity entity){
        docApprovalService.insert(entity);
        return R.ok();
    }

    @ApiOperation(value = "提交审批", produces = "application/json")
    @RequestMapping(value = "/update/{docId}" ,method = RequestMethod.GET)
    public R update(@PathVariable("docId") String docId) {
        LawRepoDocApprovalEntity docApprovalEntity = docApprovalService.findByDocId(docId);
        if (null != docApprovalEntity) {
            docApprovalEntity.setStatusNum("3");
            docApprovalEntity.setApprovalDate(new Date());
            docApprovalEntity.setApprovalName("approvalName");
            docApprovalService.update(docApprovalEntity);
        }
        return R.ok();
    }

    @RequestMapping(value = "/updateDelFlagAll" ,method = RequestMethod.GET)
    @ApiOperation(value = "全部删除审批", produces = "application/json")
    public R updateDelFlagAll(){
        docApprovalService.updateDelFlagAll("1");
        return R.ok();
    }

    @PostMapping("/deleteBatch")
    @ApiOperation(value = "批量删除", produces = "application/json")
    @ApiImplicitParam(name = "mapIds",value = "ids",paramType = "body",dataType = "body")
    public R deleteBatch(@RequestBody Map<String, Object> mapIds) {
        docApprovalService.commonUpdateDelFlagBatch("1", mapIds);
        return R.ok();
    }

}
